﻿@{
    ViewBag.Title = "Register";
    Layout = null;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="/Content/jquery-validation-1.13.1/lib/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="/Content/jquery-validation-1.13.1/dist/jquery.validate.js" type="text/javascript"></script>
    <script src="/Content/validation.sugar.js" type="text/javascript"></script>
    <script src="/Content/jquery-validation-1.13.1/lib/jquery.form.js" type="text/javascript"></script>
    <link href="/Content/jquery-validation-1.13.1/validation.sugar.css" rel="stylesheet"
        type="text/css" />
    <script type="text/javascript">
        $(function () {
            var factory = new validateFactory($("form"), "<img src=\"/Content/jquery-validation-1.13.1/error.png\" />");
            factory.init();

        });

        //用户名是否已存在
        function checkUserName() {
            //实际开发换成: ajax  async:false
            var userName = $("[name=userName]").val();
            if (userName == "admin1" || userName == "admin2") {
                return false;
            }
            return true;
        }

        //验证密码是否一致
        function confirmPassword() {
            return $("[name=password]").val() == $("[name=password2]").val();
        }

    </script>
    <style>
        td
        {
            height: 30px;
            padding: 5px;
        }
    </style>
</head>
<body>
    <h3>
        基于jquery.validate的前后台双验证</h3>
    <form method="post" class="form" id="form1" action="/home/postRegister">
    <table>
        <tr>
            <td>
                name
            </td>
            <td>
                <input type="text" name="userName">
            </td>
        </tr>
        <tr>
            <td>
                password
            </td>
            <td>
                <input type="password" name="password" />
            </td>
        </tr>
        <tr>
            <td>
                confirm password
            </td>
            <td>
                <input type="password" name="password2" />
            </td>
        </tr>
        <tr>
            <td>
                sex
            </td>
            <td>
                  <input type="radio" value="1" name="sex" />
                    男
                    <input type="radio" value="0" name="sex" />
                    女
            </td>
        </tr>
        <tr>
            <td>
                email
            </td>
            <td>
                <input type="text" name="email" />
            </td>
        </tr>
        <tr>
            <td>
                mobile
            </td>
            <td>
                <input type="text" name="mobile" />
            </td>
        </tr>
        <tr>
            <td>
                qq
            </td>
            <td>
                <input type="text" name="qq" />
            </td>
        </tr>
        <tr>
            <td>
                education
            </td>
            <td>
                <p>
                    <input type="checkbox" value="1" name="education" />
                    本科
                    <input type="checkbox" value="2" name="education" />
                    幼儿园
                    <input type="checkbox" value="3" name="education" />
                    小学
                </p>
            </td>
        </tr>
    </table>
    <button type="submit">
        submit提交(禁掉浏览器JS进行测试)</button>
    @Html.Raw(ViewBag.validationBind)
    </form>
</body>
</html>
